//组托详表

/* const {
	stringify
} = require("querystring");
 */
//右滑关闭
mui.init({
	swipeBack: true,
})
var fs = true;
var UserNO = localStorage.getItem("UserName");
window.onload = function() {

	mui.plusReady(function() {
		var currentwindow = plus.webview.currentWebview();
		if (currentwindow.TradeNO != '' && currentwindow.TradeNO != undefined) {
			$("#TradeNO").val(currentwindow.TradeNO);
			$("#SourceOrderNO").val(currentwindow.SourceOrderNO);
			$("#SupplyName").val(currentwindow.SupplyName);
			$("#WarehouseName").val(currentwindow.WarehouseName);
		} else {
			mui.toast("未带入参数。", {
				duration: '1000',
				type: 'div'
			});
		}

		//储位扫描
		$("#StorageNO").keyup(function(event) {
			console.log(event);
			if (event.keyCode == 13) {
				var StorageNO = $("#StorageNO").val();
				if (!StorageNO) {
					mui.toast("请重新扫描。", {
						duration: '1000',
						type: 'div'
					});
					$("#StorageNO").focus();
				}
				xccpostAsync("JyhstWebASHX.ashx", {
					Action: "GetStorageCheck",
					StorageNO: StorageNO
				}, function(data) {
					document.activeElement.blur();
					console.log(JSON.stringify(data))
					if (data.Code == "200") {
						$("#MaterialNO").focus();
					} else {
						$("#txtResult").val("储位编号:" + StorageNO + "不存在.");
						$("#StorageNO").val('');
						$("#StorageNO").focus();

					}
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
				}, function(error) {
					console.log("没有数据....");
					$("#StorageNO").val('');
					$("#StorageNO").focus();
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
				});
				// event.preventDefault();
				// event.stopPropagation();
			}

		});

		//上料站位扫描
		$("#MaterialNO").keyup(function(e) {

			console.log(e);
			if (e.keyCode == 13) {
				document.activeElement.blur();
				var TradeNO = $("#TradeNO").val();
				var StorageNO = $("#StorageNO").val();
				var MaterialNO = $("#MaterialNO").val();
				if (!MaterialNO) {
					mui.toast("请扫描料盘条码。", {
						duration: '1000',
						type: 'div'
					});
					MaterialNO.focus();
				}
				xccpostAsync("JyhstWebASHX.ashx", {
					Action: "PutOnSingle",
					TradeNO: TradeNO,
					StorageNO: StorageNO,
					MaterialNO: MaterialNO,
					UserNO: UserNO
				}, function(data) {
					console.log(JSON.stringify(data));
					if (data.Code == "200") {
						$("#txtResult").val(MaterialNO + "上架成功");
						$("#MaterialNO").val('');
						$("#StorageNO").val('');
						$("#StorageNO").focus();
					} else {
						mui.toast("扫描失败。" + data.Message, {
							duration: '1000',
							type: 'div'
						});
						Audios();
						$("#MaterialNO").val('');
						$("#MaterialNO").focus();

					}
					plus.nativeUI.closeWaiting();
				}, function(error) {
					console.log("没有数据....");
					$("#MaterialNO").val('');
					$("#MaterialNO").focus();
					Audios();
					plus.nativeUI.closeWaiting();
				});


			}

		});


		//关闭等待框

		plus.nativeUI.closeWaiting();
		//显示当前页面
		//mui.currentWebview.show();
	});
}

//失败报警
function Audios() {
	var audio = new Audio('../../../fonts/baojin.mp3');

	audio.play();
}